﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PointTracker
{
    public partial class Scribe : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userEmail = "";

            //if (!IsPostBack)
            {
                if (Session["User"] == null)
                {
                    Response.Redirect("/");
                }
                else if (((User)Session["User"]).role == UserRole.Scribe)
                {
                    userEmail = ((User)Session["User"]).email;
                }
            }

            GetClasses(userEmail);
        }

        protected void GetClasses(string userEmail)
        {
            List<Class> classes = PointTracker.Class.getClasses(userEmail);

            string table = "";
            foreach (Class singleClass in classes)
            {
                table += "<br /><a href='/viewEditPoints.aspx?class=" + singleClass.crn + "' " + ">" + singleClass.name + "</a>, term: " + singleClass.term + ", year: " + singleClass.year;
            }

            if (table.Equals(""))
                table = "<br />No available classes";

            divClasses.InnerHtml = table;
        }
    }
}